using MediatR;
using Microsoft.AspNetCore.Mvc;
using RBAC.ErrorCode;
using SmartHealthcare.Write.Api.Application.Command.Medicine;
using System.Threading;
using System.Threading.Tasks;

namespace SmartHealthcare.Write.Api.Controllers
{
    /// <summary>
    /// 药品管理控制器
    /// </summary>
    [ApiController]
    [Route("api/[controller]")]
    public class MedicineController : ControllerBase
    {
        private readonly IMediator _mediator;

        public MedicineController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 药品入库
        /// </summary>
        /// <param name="request">药品信息</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>操作结果</returns>
        [HttpPost("AddMedicine")]
        public Task<APIResult<bool>> AddMedicine([FromBody] AddMedicineCommand request, CancellationToken cancellationToken)
        {
            return _mediator.Send(request, cancellationToken);
        }

        /// <summary>
        /// 药品修改
        /// </summary>
        /// <param name="request">药品信息</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>操作结果</returns>
        [HttpPut("UpdateMedicine")]
        public Task<APIResult<bool>> UpdateMedicine([FromBody] UpdateMedicineCommand request, CancellationToken cancellationToken)
        {
            return _mediator.Send(request, cancellationToken);
        }

        /// <summary>
        /// 药品出库（逻辑删除）
        /// </summary>
        /// <param name="request">药品ID</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>操作结果</returns>
        [HttpPost("DeleteMedicine")]
        public Task<APIResult<bool>> DeleteMedicine([FromBody] DeleteMedicineCommand request, CancellationToken cancellationToken)
        {
            return _mediator.Send(request, cancellationToken);
        }
    }
}
